package com.twu.biblioteca.Users;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: DK
 * Date: 9/25/13
 * Time: 9:13 PM
 * To change this template use File | Settings | File Templates.
 */
public class User {

    private String username;
    private String password;
    private String emailAddress;
    private String name;
    private String phoneNumber;

    public User(String username, String password) {
        this.username = username;
        this.password = password;
    }

    private User(String username, String password, String name, String emailAddress, String phoneNumber)
    {
        this.username = username;
        this.password = password;
        this.name = name;
        this.emailAddress = emailAddress;
        this.phoneNumber = phoneNumber;
    }

    public static ArrayList<User> produceDefaultUsers()
    {
        ArrayList<User> users = new ArrayList<User>();
        users.add(new User("111-1111","1","Dhruv","dhruvkapur91@gmail.com","8864323456"));
        users.add(new User("111-1112","2","Ashish","ashi@gmail.com","9987657834"));
        users.add(new User("111-1113","3","Varsha","vershuu@gmail.com","8834786854"));
        users.add(new User("111-1114","1","Sakshi","sakshi@gmail.com","9878989121"));
        users.add(new User("111-1115","3","Sushant","susu@gmail.com","9013351487"));
        return users;
    }

    public String getName()
    {
        return name;
    }

    public String getEmailAddress()
    {
        return emailAddress;
    }

    public String getPhoneNumber()
    {
        return phoneNumber;
    }

    public boolean login(String username, String password)
    {
        if(authenticate(username,password))
        {
            this.username = username;
            this.password = password;
            this.name =  UserList.getNameOf(username);
            this.emailAddress = UserList.getEmailAddressOf(username);
            this.phoneNumber = UserList.getPhoneNumberOf(username);
            return true;
        }
        else
        {
            this.name = null;
            this.emailAddress = null;
            this.phoneNumber = null;
        }

        return false;
    }

    public User() {
        username = "0";         // wrong username and password
        password = "0";
        name = null;
        emailAddress = null;
        phoneNumber = null;
    }

    public boolean authenticate(String username, String password)
    {
        return UserList.contains(username,password);
    }

    public boolean authenticate() {
        return UserList.contains(username, password);
    }

    public boolean match(User currentUser) {
        return (currentUser.username.equals(this.username) && currentUser.password.equals(this.password));
    }
}
